using System.ComponentModel;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
    public class NotifyValidatableBaseTest
    {

		public class Mock : NotifyValidatableBase
		{
			#region Fields

			public const string PropertyMember = "Property";

			#endregion


			#region Properties

			private string property;

			[RequiredStringRule]
			[RequiredStringRule(RuleSet = "ruleset")]
			public string Property
			{
				get
				{
					return property;
				}
				set
				{
					if (property != value)
					{
						property = value;
						NotifyAndValidate(PropertyMember);
					}
				}
			}
#if (!WindowsCE)
			[RequiredStringRule]
			[RequiredStringRule(RuleSet = "ruleset")]
			public string PropertyWithExpression
			{
				get
				{
					return property;
				}
				set
				{
					if (property != value)
					{
						property = value;
						NotifyAndValidate(() => PropertyWithExpression);
					}
				}
			}
#endif
			#endregion
		}

		[TestFixture]
		public class Constructor
		{
			[Test]
			public void Simple()
			{
				var mock = new Mock();
				Assert.AreEqual(null, mock.RuleSet);
			}
		}
		[TestFixture]
		public class RuleSet
		{
			[Test]
			public void Simple()
			{
				var mock = new Mock()
				{
					RuleSet = "ruleSet"
				};
				Assert.AreEqual("RULESET", mock.RuleSet);
			}
		}


		[TestFixture]
		public class PropertyChanged
		{

			private bool eventFired;

			[Test]
			public void Simple()
			{
				var mock = new Mock();

				mock.PropertyChanged += mock_PropertyChanged;

				mock.Property = "Foo";

				Assert.IsTrue(eventFired);
			}
            
#if (!WindowsCE)
			[Test]
			public void Expression()
			{
				var mock = new Mock();

				mock.PropertyChanged += mock_PropertyChanged;

				mock.PropertyWithExpression = "Foo";

				Assert.IsTrue(eventFired);
			}
#endif

			void mock_PropertyChanged(object sender, PropertyChangedEventArgs e)
			{
					eventFired = true;
			}

		}

	}
}